package com.scsoft.dataacceptor.mongo;

import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.WriteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

@Component
public class MongoCollectData {
	@Autowired
	private MongoTemplate mongoCollectTemplate;
	
	@Value("${app.collection.collect}")
	private String srcDataTable;

	public int saveSrcData(String suffix,DBObject srcData) {
		String collection = srcDataTable + "-" + suffix;
		DBCollection dbCollection = mongoCollectTemplate.getCollection(collection);
		WriteResult wr = dbCollection.save(srcData);
		return wr.getN();
	}

	public int saveSrcData(DBObject srcData) {
		DBCollection dbCollection = mongoCollectTemplate.getCollection(srcDataTable);
		WriteResult wr = dbCollection.save(srcData);
		return wr.getN();
	}
}
